var myChart, myChart2;

var option = {
    
       
    title : {
        text: '上证指数',
        show: false,
    }, 
    legend: {
        data:['上证指数'],
        show: false,
    },
    toolbox: {
        show : false,
    },
    dataZoom : {
        show : false,
        realtime: true,
        start : 0,
        end : 100
    },
    xAxis : [
        {
            type : 'category',
            boundaryGap : true,
            show: false,

            axisTick: {onGap:false},
            splitLine: {show:false},
            data : [
                "2013/1/24", "2013/1/25", "2013/1/28", "2013/1/29","2013/1/29",
                "2013/1/24", "2013/1/25", "2013/1/28", "2013/1/29","2013/1/29",
                "2013/1/24", "2013/1/25", "2013/1/28", "2013/1/29","2013/1/29",
                "2013/1/24", "2013/1/25", "2013/1/28", "2013/1/29","2013/1/29",
                "2013/1/24", "2013/1/25", "2013/1/28", "2013/1/29","2013/1/29",
                "2013/1/24", "2013/1/25", "2013/1/28", "2013/1/29","2013/1/29",
                "2013/1/24", "2013/1/25", "2013/1/28", "2013/1/29","2013/1/29",
                "2013/1/24", "2013/1/25", "2013/1/28", "2013/1/29","2013/1/29",
                "2013/1/24", "2013/1/25", "2013/1/28", "2013/1/29","2013/1/29",
                "2013/1/24", "2013/1/25", "2013/1/28", "2013/1/29","2013/1/29",
            ]
        }
    ],
    yAxis : [
        {
            type : 'value',
            scale:true,
            boundaryGap: [0.01, 0.01]
        }
    ],
    series : [
        {
            name:'上证指数',
            type:'k',
            data:[ // 开盘，收盘，最低，最高
                [20.26,22.6,19.3,24.94],
                [20.34,33.6,19.3,24.94],
                [20.26,22.6,19.3,24.94],
                [20.26,22.6,19.3,24.94],
                [20.26,22.6,19.3,24.94],
                [20.26,22.6,19.3,24.94],
                [20.26,22.6,19.3,24.94],
                [20.26,22.6,19.3,24.94],
                [20.26,22.6,19.3,24.94],
                [20.26,22.6,19.3,24.94],
                [20.26,22.6,19.3,24.94],
                [20.26,22.6,19.3,24.94],
                [20.26,22.6,19.3,24.94],
                [20.26,22.6,19.3,24.94],
                [20.26,22.6,19.3,24.94],
                [20.26,22.6,19.3,24.94],
                [20.26,22.6,19.3,24.94],
                [20.26,22.6,19.3,24.94],
                [20.26,22.6,19.3,24.94],
                [20.26,22.6,19.3,24.94],
                
            ]
        }
    ]
};

var option2 = {
    title : {
       
        show: false
    },
    tooltip : {
        trigger: 'axis',
        show: false
    },
    legend: {
        data:['number'],
        show: false
    },
    toolbox: {
        show : false,
    },
    calculable : true,
    xAxis : [
        {
            type : 'category',
            show: false,
            data : ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月']
        }
    ],
    yAxis : [
        {
            name : '单位 (万)',
            type : 'value'
        }
    ],
    series : [
        {
            name:'降水量',
            type:'bar',
            data:[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3],
        }
    ]
};

require.config({
    packages: [
        {
            name: 'echarts',
            location: '../js/lib',
            main: 'echarts'
        }
    ]
});
require(
    [
        'echarts',
        'echarts/chart/k',
        'echarts/chart/bar',
        'echarts/chart/line',
    ],
    function (ec) {
        refresh(ec);
    }
);


$(document).ready(function(){
    $(".item").click(function(){
        $(".item").removeClass("active");
        $(this).addClass("active");
        var type = $(this).attr("data-type");
        getOptions(type);
    });
});

function refresh(ec) {
        if (!myChart || !myChart2) {
            myChart = ec.init(document.getElementById('main'));
            myChart2 = ec.init(document.getElementById('main2'));
        }
        myChart.setOption(option);
        myChart2.setOption(option2);
}
// 登陆的ajax
function getOptions(data) {
    $.ajax({
        type: "POST",//方法类型
        dataType: "json",//预期服务器返回的数据类型
        url: "/users/login" ,//url
        data: data,
        success: function (result) {
            // 更新options.baseOption.xAxis 中的data的长度
            // 更新options.baseOption.series 中的数据
            // refresh()
        },
        error : function() {
            option.series = [
                    // 这个是用来占位的. 先不用管
                    {
                        name:'1',
                        type:'line',
                        data:[],
                        
                    },
                    // 这个是日线图demo
                    {
                        name:'2',
                        type:'line',
                        data:[1, -21, 2, 5, 3, 2, 0],
                        
                    }
                ];
            
                

            refresh();
        }
    });
}




